from django.db import models
from django.contrib.auth.models import AbstractUser


class System(models.Model):
    hostname = models.CharField(max_length=255, verbose_name="主机名")
    os = models.CharField(max_length=100, verbose_name="操作系统")
    os_version = models.CharField(max_length=100, verbose_name="操作系统版本")
    arch = models.CharField(max_length=50, verbose_name="系统架构")
    cpu_model = models.CharField(max_length=255, verbose_name="CPU型号")
    cpu_cores = models.IntegerField(verbose_name="CPU核心数")
    cpu_usage = models.FloatField(verbose_name="CPU使用率")
    memory_total = models.BigIntegerField(verbose_name="总内存MB")
    memory_used = models.BigIntegerField(verbose_name="已用内存MB")
    memory_usage = models.FloatField(verbose_name="内存使用率")
    disk_total = models.BigIntegerField(verbose_name="总磁盘空间GB")
    disk_used = models.BigIntegerField(verbose_name="已用磁盘空间GB")
    disk_usage = models.FloatField(verbose_name="磁盘使用率")
    network_in = models.BigIntegerField(verbose_name="网络入流量MB")
    network_out = models.BigIntegerField(verbose_name="网络出流量MB")
    uptime = models.BigIntegerField(verbose_name="系统运行时长秒")
    load_avg_1 = models.FloatField(verbose_name="1分钟负载")
    load_avg_5 = models.FloatField(verbose_name="5分钟负载")
    load_avg_15 = models.FloatField(verbose_name="15分钟负载")
    process_count = models.IntegerField(verbose_name="进程数")
    last_update_time = models.BigIntegerField(verbose_name="最后更新时间")

    class Meta:
        db_table = 'system_info'
        verbose_name = '系统信息'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.hostname


class UserProfile(AbstractUser):
    class Meta:
        db_table = 'auth_user'  # 保持原来名字，方便使用，不写默认名字是user_userprofile

    phone = models.CharField(max_length=11, verbose_name='电话号码', null=True, blank=True)
